#!/bin/bash
#
# Script: rmdom.sh
# Description: Domain removal script.
#
# Author: Gary Locke
#
# Usage: ./rmdom.sh <domain>
#
# Changelog:
# - 5/21/2013 - Initial write.
#

if [[ "$(whoami)" != "root" ]];then
    echo -ne "\nThis script must be run as root.\n"; exit 1
fi

epoch="$(date +"%s")"

domain=$1
while true;do
    if [[ -z "$domain" ]];then
        read -e -p "Enter domain name (e.g. domain.com): " domain
    else
        break
    fi
done

if [[ -n $(ps aux|grep -m1 -w httpd|grep -v grep) ]];then
    HTTPD_RUNNING=1
fi

if [[ -n $(ps aux|grep -m1 -w lighttpd|grep -v grep) ]];then
    LIGHTTPD_RUNNING=1
fi

if [[ -n $(ps aux|grep -m1 -w nginx|grep -v grep) ]];then
    NGINX_RUNNING=1
fi

if [[ "$HTTPD_RUNNING" -eq 1 ]];then
    read -e -p "Enter Apache client config path: " _apache_client_conf
    echo -ne "Backing up client conf to $_apache_client_conf.$epoch ... "
    cp -a "$_apache_client_conf" "$_apache_client_conf.$epoch"
    if [[ -e "$_apache_client_conf.$epoch" ]];then
        echo "Success!"
    else
        echo -ne "\nBackup failed. Quitting.\n"
        exit 1
    fi



fi

exit
